using Assets.Pixelation.Example.Scripts;
using UnityEngine;

namespace Assets.Pixelation.Scripts
{
	[ExecuteInEditMode]
	[AddComponentMenu("Image Effects/Color Adjustments/Chunky")]
	public class Chunky : ImageEffectBase
	{
		public Texture2D SprTex;

		public Color Color = Color.white;

		private void OnRenderImage(RenderTexture source, RenderTexture destination)
		{
			float num = Camera.main.pixelWidth;
			float num2 = Camera.main.pixelHeight;
			Vector2 vector = new Vector2(num / (float)SprTex.height, num2 / (float)SprTex.height);
			Vector2 vector2 = new Vector2(1f / vector.x, 1f / vector.y);
			base.material.SetVector("BlockCount", vector);
			base.material.SetVector("BlockSize", vector2);
			base.material.SetColor("_Color", Color);
			base.material.SetTexture("_SprTex", SprTex);
			Graphics.Blit(source, destination, base.material);
		}
	}
}
